<?php

namespace App\Http\Requests\Role;

use Illuminate\Foundation\Http\FormRequest;

class StoreRoleRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true; // 在实际应用中，你可能需要根据用户权限来判断
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'name' => 'required|string|max:255|unique:roles',
            'slug' => 'required|string|max:255|unique:roles',
            'description' => 'nullable|string',
            'status' => 'required|boolean',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息。
     */
    public function messages(): array
    {
        return [
            'name.required' => '角色名称不能为空',
            'name.unique' => '角色名称已存在',
            'slug.required' => '角色标识不能为空',
            'slug.unique' => '角色标识已存在',
            'status.required' => '状态不能为空',
        ];
    }
}
